using UnityEngine;
using System.Collections;

/* 
 * 定义一次进攻行为，包括持续时间，伤害范围，伤害大小等数据
 */

public class HitAction : MonoBehaviour{
	
	public DamageInfo dmgInfo;
	 
	// creator is solder object
	private Square creator;

	public Square Creator
	{
		get {return creator;}
		set {creator = value; Bind();}
	}
	
	public BoxCollider actionSphere;

	public Vector3 emitOffset;

	public float durationTime;

	public ArrayList lstIgnore;

	protected float startTime;

	// Use this for initialization
	void Start () {
		startTime = Time.time;
		lstIgnore = new ArrayList ();

	}

	void Bind () {
		this.transform.position = creator.transform.position;
		this.transform.rotation = creator.transform.rotation;
		this.transform.Translate(this.emitOffset);

		this.gameObject.GetComponent<Camp> ().camp = creator.GetComponent<Camp> ().camp;
	}

	// Update is called once per frame
	void Update () {
		if (Time.time > startTime + durationTime)
			Destroy (gameObject);
	}

	public bool CheckValid(Body body)
	{
		foreach (Body gbody in lstIgnore) {
			if(gbody.Equals(body))
				return false;
		}

		return true;
	}

	public void AddIgnoreObj(Body body)
	{
		lstIgnore.Add (body);
	}
}
